package com.pzj.dormitory.controller;


import com.pzj.dormitory.entity.Building;
import com.pzj.dormitory.form.SearchForm;
import com.pzj.dormitory.service.impl.BuildingServiceImpl;
import com.pzj.dormitory.util.ResultVOUtil;
import com.pzj.dormitory.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-04-28
 */
@RestController
@RequestMapping("/building")
public class BuildingController {


    @Autowired
    private BuildingServiceImpl buildingService;

    @PutMapping("/save")
    public ResultVO save(@RequestBody Building building){
        boolean save = buildingService.save(building);
        if (!save) return ResultVOUtil.fail();
        return ResultVOUtil.success(null);
    }

    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVO list(@PathVariable("pageNum") Integer pageNum,@PathVariable("pageSize") Integer pageSize){
        return ResultVOUtil.success(buildingService.list(pageNum,pageSize));
    }

    @GetMapping("/search")
    public ResultVO search(SearchForm searchForm){
        return ResultVOUtil.success(buildingService.search(searchForm));
    }

    @GetMapping("/list")
    public  ResultVO list(){
        return  ResultVOUtil.success(buildingService.list());
    }

    @GetMapping("/findById/{id}")
    public ResultVO findById(@PathVariable("id") Integer id){

        return ResultVOUtil.success(buildingService.getById(id));
    }

    @DeleteMapping("/deleteById/{id}")
    public ResultVO deleteById(@PathVariable("id") Integer id){
        return ResultVOUtil.success(buildingService.deleteById(id));
    }

}

